<?php if (!defined('THINK_PATH')) exit();?>﻿<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="/Public/js/checked.js"></script>
    <title><?php echo ($title); ?></title>
    <link rel="stylesheet" type="text/css" href="/Public/css/reset.css" />
    <link rel="stylesheet" type="text/css" href="/Public/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/Public/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="/Public/css/ureg.css" />
    <script language="JavaScript">
        function nameCheck(){
            var username=document.getElementById('nickname').value;
            var result=document.getElementById("result");
            var messages=document.getElementById("messages");
            var CheckUsername = /^([\u4e00-\u9fa5]{3,15}$|^[0-9a-zA-Z_]{6,30})$/;
            var res_1=CheckUsername.test(username);
            if(res_1){
                $.post("<?php echo U('/nameCheck');?>",{username:username},function(msg){
                    if(msg=="0"){
                        document.getElementById('errorImg').src="/Public/images/tick.png";
                        messages.innerHTML="用户名可用";
                        result.style.display="block";
                        $(" #result").fadeOut(2000);
                    }else if(msg=="1"){
                        document.getElementById('errorImg').src="/Public/images/error.jpg";
                        messages.innerHTML="用户名已被注册";
                        result.style.display="block";
                        document.getElementById('nickname').focus();

                    }else{
                        alert(msg);
                    }
                });
            }else{
                document.getElementById("hint1").innerHTML = "× 错误";
                userinfo.nickname.focus();
                return false;
            }
        }

        function checkUserInfo() {
            var nickname = userinfo.nickname.value;
            var xm = userinfo.xm.value;
            var sex = userinfo.gender.value;
            var age = userinfo.age.value;
            var qq = userinfo.qq.value;
            var address=userinfo.address.value;
            var result=document.getElementById("result");
            var messages=document.getElementById("messages");

            //昵称正则
            var CheckNickname = /^([\u4e00-\u9fa5]{3,15}$|^[0-9a-zA-Z_]{6,30})$/;
            var res_1=CheckNickname.test(nickname);
            if(nickname == '' || !res_1) {
                document.getElementById("hint1").innerHTML = "× 错误";
                userinfo.nickname.focus();
                return false;
            }
            else {
                document.getElementById("hint1").innerHTML = "<span style = 'color:green;'>√ 正确</span>";
            }

            //姓名正则
            var Checkxm = /^[\u4E00-\u9FA5]{2,7}$|^[\u4E00-\u9FA5]{2,5}(?:·[\u4E00-\u9FA5]{2,5})$|^[a-zA-Z]{1,30}$/;
            var res_2=Checkxm.test(xm);
            if(xm == '' || !res_2) {
                document.getElementById("hint2").innerHTML = "× 错误";
                userinfo.xm.focus();
                return false;
            }
            else {
                document.getElementById("hint2").innerHTML = "<span style = 'color:green;'>√ 正确</span>";
            }

            //qq正则
            var Checkqq = /^[1-9][0-9]{4,10}$/;
            var res_3=Checkqq.test(qq);
            if(qq == '' || !res_3) {
                document.getElementById("hint4").innerHTML = "× 错误";
                userinfo.qq.focus();
                return false;
            }
            else {
                document.getElementById("hint4").innerHTML = "<span style = 'color:green;'>√ 正确</span>";
            }

            //地址正则
            var CheckAddress = /^[\u4E00-\u9FFFa-zA-Z\d-]+$/;
            var res_4=CheckAddress.test(address);
            if(address == '' || !res_4) {
                document.getElementById("hint5").innerHTML = "× 错误";
                userinfo.address.focus();
                return false;
            }
            else {
                document.getElementById("hint5").innerHTML = "<span style = 'color:green;'>√ 正确</span>";
            }
            //全部通过
            if(res_1&& res_2 && res_3 &&res_4){
                $.post("<?php echo U('/userInfo');?>",{nickname:nickname,xm:xm,sex:sex,age:age,qq:qq,address:address},function(msg){
                    if(msg=="0"){
                        result.style.display="none";
                        if(result.style.display=="none"){
                            window.location.href="<?php echo U('/tips');?>";
                        }else{
                            messages.innerHTML="错误信息未处理完成。";
                            result.style.display="block";
                        }
                    }else if(msg=="1"){
                        messages.innerHTML="录入数据错误。";
                        result.style.display="block";
                    }else if(msg=="2"){
                        alert("对不起！您申请的验证码已过期");
                        window.location.href="<?php echo U('/mstreg');?>";
                    }else if(msg=="3"){
                        messages.innerHTML="数据库连接错误。";
                        result.style.display="block";
                    }else if(msg=="4"){
                        alert("对不起！您无权进入该页面。");
                        window.location.href="<?php echo U('/mstreg');?>";
                    }else if(msg=="5"){
                        window.location.href="<?php echo U('/tips');?>";
                    }else if(msg=="6"){
                        messages.innerHTML="用户名已被注册。";
                        result.style.display="block";
                    }else{
                        alert(msg);
                    }
                });
            }else{
                messages.innerHTML="错误信息未处理完成。";
                result.style.display="block";
            }

        }
    </script>
</head>
<body>

<!--------------------------------导航栏-------------------------------------->
<div id="nav">
    <div class="container">
        <div class="row" style="margin-top:0px;">
            <div class="col-lg-12" style="background-color: #ff2d4b;">
                <img src="/Public/images/LOGO2.png"  class="img-responsive" onclick="back(this)" style="cursor: pointer;"/>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function back(obj){
        obj.src=window.location.href="<?php echo U('/index');?>";
    }
</script>
<div class="container">
    <div class="row" style="margin-top:20px;">
        <div class="col-lg-6">
            <img src="/Public/images/LOGO.png" class="img-responsive"/>
        </div>
    </div>

    <div class="row" style="margin-top:20px;">
        <div class="col-lg-6">
            <img src="/Public/images/people.png" class="img-responsive"/>
        </div>
        <div class="col-lg-6">
            <div id="ureg">
                <div style="width: 100%; height: 100px; text-align: center;">
                    <span style="color: #dadada;    text-align: center;    line-height: 100px;    padding-top: 30px;">
                        <div style="float: left;">///////////////////</div>
                        <label style="font-family:Arial,'宋体';    font-size: 32px;    color: #ff2d4b;">会员注册</label>
                        <div style="float: right;">///////////////////</div>
                    </span>
                </div>
                <!--error tips-->
                <!--error tips start-->
<div id="result">
    <img id="errorImg" src="/Public/images/error.jpg" alt="错误提示"/>
    <span id="messages"></span>
</div>
<!--error tips end-->

                <!--	用户注册表单	-->
                <div>
                    <form method="post" name="userinfo" class="" role="form">
                        <table align="center" width="86%">
                            <tr>
                                <th width="20%">昵称：</th>
                                <td width="54%">
                                    <input type="text" name="nickname" class="tbox form-control" id="nickname" onblur="nameCheck()"
                                           placeholder="6-15位字母、数字或符号"/>
                                </td>
                                <td width="12%">
                                    <span id="hint1">*</span>
                                </td>
                            </tr>
                            <tr>
                                <th>姓名：</th>
                                <td><input type="text" name="xm" class="tbox form-control" id="xm"
                                           placeholder="请输入您的真实姓名"/></td>
                                <td><span id="hint2">*</span></td>
                            </tr>
                            <tr>
                                <th>性别：</th>
                                <td>
                                    <label style="cursor: pointer;"><input type="radio" name="gender" value="女" checked="true"/>女</label>
                                    &nbsp;
                                    &nbsp;
                                    <label style="cursor: pointer;"><input type="radio" name="gender" value="男"/>男</label>
                                </td>

                            </tr>
                            <tr>
                                <th>年龄：</th>
                                <td>
                                    <select style="width: 70px;" name="age" id="age" style="border-radius:5px;">
                                        <?php
 for($i=14;$i<71;$i++){ ?>
                                        <option value="<?php echo $i;?>"><?php echo $i;?></option>
                                        <?php
 } ?>
                                    </select>
                                </td>

                            </tr>
                            <tr>
                                <th>QQ：</th>
                                <td><input type="text" name="qq" class="tbox form-control" id="qq" placeholder="请输入您的联系QQ号码"/></td>
                                <td><span id="hint4">*</span></td>
                            </tr>
                            <tr>
                                <th>详细地址：</th>
                                <td><input type="text" name="address" id="address" class="tbox form-control" placeholder="请输入您的详细住址"/></td>
                                <td><span id="hint5">*</span></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td style="text-align: center;"><input type="button" onclick="checkUserInfo()" name="sub" id="btn" value="注&nbsp;&nbsp;&nbsp;册" class="btn"/></td>
                            </tr>
                        </table>
                        <div style="margin-bottom:12%;"></div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!--	引入底部	-->
﻿<div id = "footer">
    <div>
        <a href = "#">关于我们</a> <a href = "#">联系客服</a> <a href = "#">招聘信息</a> <a href = "#">意见反馈</a> <a href = "#">版权投诉</a>
    </div>
    <div style = "color:#ffffff;">&copy;2015 深圳市妈妈好菜网络科技有限公司 版权所有 蜀ICP备14025970号-1</div>
</div>
</body>
</html>